//
//  BranchNormalModel.m
//  ShangHaiHuDongApp
//
//  Created by apple on 17/8/5.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "BranchNormalModel.h"

@implementation BranchNormalModel
- (NSString *)description{
    return [self yy_modelDescription];
}


-(void)calculateTitleHeightAndCellHeightWithBeignY:(CGFloat)beginY itemTextHeight:(CGFloat)itemTextHeight{
    NSMutableAttributedString * titleAttributedString = [[NSMutableAttributedString alloc]initWithString:self.titleString];
    //设置字体大小
    [titleAttributedString addAttribute:NSFontAttributeName value:LYPFONT(16) range:NSMakeRange(0, self.titleString.length)];
    //设置字间距
    [titleAttributedString addAttribute:NSKernAttributeName value:@(ItemWidth * 15) range:NSMakeRange(self.TYPESTR.length + 1, 1)];
    //设置行间距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:ItemHeight * 22];
    [titleAttributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, self.titleString.length)];
    self.titleAttributedString = titleAttributedString;
    //计算头部高度
//    self.titleHeight = [self.titleString boundingRectWithSize:CGSizeMake(ItemWidth * 642, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : LYPFONT(16) , NSKernAttributeName : @(ItemWidth * 15) , NSParagraphStyleAttributeName : paragraphStyle } context:nil].size.height;
    self.titleHeight = [self.titleAttributedString boundingRectWithSize:CGSizeMake(ItemWidth * 642, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height;
    //计算cell高度
    
    //判断有是否大于1行，小于1行系统自动添加一个行间距
    CGFloat lineNumberHeight = self.titleHeight - 22 * ItemHeight - itemTextHeight;
    if (lineNumberHeight > 0.0001) {
        //多行
    }
    else{
        //单行
        self.titleHeight = self.titleHeight - 22 * ItemHeight + 0.0001;
        [self.titleAttributedString removeAttribute:NSParagraphStyleAttributeName range:NSMakeRange(0, self.titleString.length)];
    }
    NSInteger type = [self.typeString integerValue];
    switch (type) {
        case 1:
        {
            //设置字体颜色
            [self.titleAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor themeColor] range:NSMakeRange(0, self.TYPESTR.length + 2)];
            self.cellHeight = self.titleHeight + beginY + ItemHeight * 214;
            break;
        }
        case 2:
        {
            //设置字体颜色
            [self.titleAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor zj_colorWithHexString:@"558b2f"] range:NSMakeRange(0, self.TYPESTR.length + 2)];
            self.cellHeight = self.titleHeight + beginY + ItemHeight * 238;
            break;
        }
        case 3:
        {
            //设置字体颜色
            [self.titleAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor zj_colorWithHexString:@"ff7200"] range:NSMakeRange(0, self.TYPESTR.length + 2)];
            self.cellHeight = self.titleHeight + beginY + ItemHeight * 181;
            break;
        }
        case 4:
        {
            //设置字体颜色
            [self.titleAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor themeColor] range:NSMakeRange(0, self.TYPESTR.length + 2)];
            self.cellHeight = self.titleHeight + beginY + ItemHeight * 151;
            break;
        }
        case 5://我的考试
        {
            //设置字体颜色
            [self.titleAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor zj_colorWithHexString:@"fca301"] range:NSMakeRange(0, self.TYPESTR.length + 2)];
            self.cellHeight = self.titleHeight + beginY + ItemHeight * (151 - 60);
            break;
        }
        default:
            break;
    }
    
}





@end
